import unittest
from common.dbutil import dbuilt
from config import BASE_DIR
from config import BODY
from api.login_api import LoginApi
from api.emp_api import EmpApi
from common import verify_emp

class TestEmp(unittest.TestCase):
    mobile = "17777888212"
    au_headers = None
    emp_id = None

    @classmethod
    def setUpClass(cls) -> None:
        print('类前置:删除指定员工')
        sql = f"delete from bs_user where mobile = '{cls.mobile}'"
        n = dbuilt.iud_data(sql)
        print(n)

        login_obj = LoginApi()
        body = BODY
        cls.au_headers = login_obj.get_au_headers(body)
        print(f'au_headers = {cls.au_headers}')

    @classmethod
    def tearDownClass(cls) -> None:
        print('类前置:删除指定员工')
        sql = f"delete from bs_user where mobile = '{cls.mobile}'"
        n = dbuilt.iud_data(sql)
        print(n)

    def test_emp(self):
        emp_obj = EmpApi()
        add_body = {"username": "楚枫喜欢甜美的妞",
                    "mobile": self.mobile,
                    "timeOfEntry": "2021-11-01",
                    "formOfEmployment": 1,
                    "workNumber": "15832585",
                    "departmentName": "测试1部",
                    "departmentId": "1452483254694281216",
                    "correctionTime": "2021-11-29T16:00:00.000Z"}
        resposne = emp_obj.add_emp(add_body,self.au_headers)
        json_data = resposne.json()
        print(f'新增员工的结果为{json_data}')
        verify_emp.emp_assert(self,resposne)

        self.emp_id = json_data['data']['id']
        print(f'新增员工id为{self.emp_id}')

        response = emp_obj.query_emp(self.emp_id,self.au_headers)
        json_data = resposne.json()
        print(f'查询员工的结果为{json_data}')
        verify_emp.emp_assert(self, resposne)


        modify_body = {"username": "楚枫大战龙傲天"}
        response = emp_obj.modify_emp(self.emp_id,modify_body,self.au_headers)
        json_data = resposne.json()
        print(f'删除员工的结果为{json_data}')
        verify_emp.emp_assert(self, resposne)

        response = emp_obj.delete_emp(self.emp_id,self.au_headers)
        json_data = resposne.json()
        print(f'删除员工的结果为{json_data}')
        verify_emp.emp_assert(self, resposne)

